package com.lemon.smartsafetynew.net.services;

import android.content.Context;
import android.util.Log;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.http.service.BaseHttpServices;
import com.lemon.smartsafetynew.entity.air.AirItmeVo;
import com.lemon.smartsafetynew.entity.common.DateTypeEnum;
import com.lemon.smartsafetynew.entity.electrical.ElectricalCompanyVo;
import com.lemon.smartsafetynew.entity.highDanger.HighDangerItemVo;
import com.lemon.smartsafetynew.entity.monitor.MonitorDetailItemVo;
import com.lemon.smartsafetynew.entity.monitor.MonitorItemVo;
import com.lemon.smartsafetynew.entity.monitor.MonitorSensorResult;
import com.lemon.smartsafetynew.entity.monitor.MonitorStatisticResultVo;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolTaskVo;
import com.lemon.smartsafetynew.entity.tank.TankItemVo;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;

/**
 * Created by Andrew on 2017/8/8.
 */

public class MonitorServices extends BaseHttpServices {

    public static final String TAG = "MonitorServices";

    public MonitorServices(Context context) {
        super(context);
    }

    /**
     * 初始化，等同使用构造函数
     *
     * @return
     */
    public static MonitorServices init() {
        return new MonitorServices(IApplication.context());
    }


    /**
     * 初始化，等同使用构造函数
     *
     * @param context
     * @return
     */
    public static MonitorServices init(Context context) {
        return new MonitorServices(context);
    }


    /**
     * 获得监控点的所有数量，异常个数，正常个数，无数据个数
     */
    public void getRealTimeMonitorPointAllStatus() {

        HandlerCallback<List<Integer>> callback = new HandlerCallback<List<Integer>>(KeyConstants.URL_GET_MONITOR_ALL_STATUS) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_ALL_STATUS, Constants.MONITOR_V1);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .build().execute(callback);

    }

    /**
     * 获得传感器的所有数量，异常个数，正常个数，无数据个数
     */
    public void getRealTimeMonitorPointAllSensorStatus() {

        HandlerCallback<List<Integer>> callback = new HandlerCallback<List<Integer>>(KeyConstants.URL_GET_MONITOR_ALL_SENSOR) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_ALL_SENSOR, Constants.MONITOR_V1);

        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .build().execute(callback);

    }

    /**
     * 获得异常指数和排名前三的异常检测点
     */
    public void getRealTimeMonitorPointAllAlarmAvg(LemonRequestParams params, DateTypeEnum dateTypeEnum) {

        HandlerCallback<MonitorStatisticResultVo> callback = new HandlerCallback<MonitorStatisticResultVo>(KeyConstants.URL_GET_MONITOR_ALARM_AVG + dateTypeEnum.getName()) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_ALARM_AVG + dateTypeEnum.getName(), Constants.MONITOR_V1);

        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获得监测点列表
     */
    public void getMonitorPointList(RefreshType type) {

        HandlerCallback<List<MonitorItemVo>> callback = new HandlerCallback<List<MonitorItemVo>>(KeyConstants.URL_GET_MONITOR_DETAIL_LIST) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_DETAIL_LIST, Constants.MONITOR_V1);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .build().execute(callback);

    }

    /**
     * 获得监测点传感器列表
     */
    public void getMonitorPointSensorList(LemonRequestParams params) {
        HandlerCallback<List<MonitorDetailItemVo>> callback = new HandlerCallback<List<MonitorDetailItemVo>>(KeyConstants.URL_GET_MONITOR_SENSOR_LIST) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_SENSOR_LIST, Constants.MONITOR_V1);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获得监测点传感器的实时数据
     */
    public void getSensorRealTimeData(LemonRequestParams params) {
        HandlerCallback<MonitorSensorResult> callback = new HandlerCallback<MonitorSensorResult>(KeyConstants.URL_GET_MONITOR_SENSOR_REAL_TIME) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_SENSOR_REAL_TIME_DATA, Constants.MONITOR_V1);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);
    }

    /**
     * 获得企业列表
     */
    public void getMonitorVideoCompanyList(RefreshType type, LemonRequestParams params) {

        HandlerCallback<List<ElectricalCompanyVo>> callback = new HandlerCallback<List<ElectricalCompanyVo>>(KeyConstants.URL_GET_MONITOR_HAS_VIDEO_COMPANY_LIST) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_HAS_VIDEO_COMPANY_LIST, Constants.SERVER_V2);
        OkHttpUtils.post()
                .params(params)
                .tag(callback.getTag())
                .url(serverUrl)
                .build().execute(callback);

    }

    /**
     * 获得储罐列表
     */
    public void getTankList(RefreshType type, LemonRequestParams params) {

        HandlerCallback<List<TankItemVo>> callback = new HandlerCallback<List<TankItemVo>>(KeyConstants.URL_GET_MONITOR_TANK_LIST) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_TANK_LIST, Constants.MONITOR_V1);
        //String serverUrl = UrlInfo.GET_MONITOR_TANK_LIST;
        OkHttpUtils.post()
                .params(params)
                .tag(callback.getTag())
                .url(serverUrl)
                .build().execute(callback);

    }

    /**
     * 获得气体列表
     */
    public void getAirList(RefreshType type, LemonRequestParams params) {

        HandlerCallback<List<AirItmeVo>> callback = new HandlerCallback<List<AirItmeVo>>(KeyConstants.URL_GET_MONITOR_AIR_LIST) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_AIR_LIST, Constants.MONITOR_V1);
        //String serverUrl = UrlInfo.GET_MONITOR_AIR_LIST;
        OkHttpUtils.post()
                .params(params)
                .tag(callback.getTag())
                .url(serverUrl)
                .build().execute(callback);

    }

    /**
     * 获得高危工艺列表
     */
    public void getHighDangerList(RefreshType type, LemonRequestParams params) {

        HandlerCallback<List<HighDangerItemVo>> callback = new HandlerCallback<List<HighDangerItemVo>>(KeyConstants.URL_GET_MONITOR_HIGH_DANGER_LIST) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_MONITOR_HIGH_DANGER_LIST, Constants.MONITOR_V1);
        //String serverUrl = UrlInfo.GET_MONITOR_HIGH_DANGER_LIST;
        OkHttpUtils.post()
                .params(params)
                .tag(callback.getTag())
                .url(serverUrl)
                .build().execute(callback);

    }

}
